from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time

def wjx():
    # 配置 Chrome 无痕模式
    chrome_options = Options()
    chrome_options.add_argument("--incognito")  # 无痕模式
    chrome_options.add_argument("--start-maximized")  # 最大化窗口

    # 启动浏览器
    driver = webdriver.Chrome(options=chrome_options)

    try:
        # 打开目标网页
        driver.get("https://www.wjx.cn/vm/wplWdLP.aspx#")

        # 等待页面加载
        time.sleep(2)

        # 题目数量
        for i in range(10):
            xpath = '//*[@id="div{}"]/div[2]/div[1]/div'.format(i + 1)
            # 找到元素并点击
            target_div = driver.find_element(By.XPATH, xpath)
            target_div.click()

        # 最后一题特殊处理
        xpath_last = '//*[@id="div11"]/div[2]/div[5]/div'
        # 找到元素并点击
        target_div = driver.find_element(By.XPATH, xpath_last)
        target_div.click()

        # 提交
        submit_button = driver.find_element(By.ID, "ctlNext")
        submit_button.click()

        # 等待几秒观察结果
        time.sleep(5)

    finally:
        driver.quit()

def run(k:int):
    for i in range(k):
        wjx()
        print("第{}次投票，已完成！".format(i+1))

if __name__ == '__main__':
    run(10)